/*******************************************************************************
 * 1. 시 스 템 : 농협보험 이미지처리 시스템
 * 2. 프로그램 : LINebDstbtThread.java
 * 3. 개 요    : 생명사고지급 분배 Agent
 * 4. 작 성 자 : wonsama
 * 5. 작 성 일 : 2011. 12. 29
 * 6. 소스버전 : 1.0.1 
 * 1.0.1 : TRY CATCH 구문 추가됨 현재 10시간 정도 돌면 NULL EXCEPTION 발생 함
 ********************************************************************************/

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.nhim.common.EnvManager;
import com.nhim.common.Environment;
import com.nhim.pool.ConnectionPool;
import com.nhim.pool.WQueryHelper;
import com.nhim.utility.COMUtil;
import com.nhim.utility.WStringUtil;

public class LINebDstbtThread extends Thread{


	////////////////////////////////////////////////////////////////////
	//
	//	DB FIELDS
	//

	private final String SPLIT = ",";	// |로 나누면 문제 발생 흠...
	private final String[] G_CODES = { "244001" , "244002" , "244003" };				//GRP_CODE : 244000

	private final String SUBS_NO = "SUBS_NO";
	private final String SUBS_TYPE = "SUBS_TYPE";
	private final String JDG_GRDE_CODE = "JDG_GRDE_CODE";
	private final String IS_SAVE_GD = "IS_SAVE_GD";
	private final String JDG_NO = "JDG_NO";

	////////////////////////////////////////////////////////////////////
	//
	//	AGENT INFO
	//
	String agentName = "NHImDstbtAgent";
	String moduleName = "LINebDstbtThread";
	String server = "";
	String agentTime = "";

	////////////////////////////////////////////////////////////////////////////////////////
	//
	//	INIT
	//

	/**
	 * 생성자
	 */
	public LINebDstbtThread(){
	}

	////////////////////////////////////////////////////////////////////////////////////////
	//
	//	EXTENDS THREAD
	//

	/**
	 * RUN : 구동중인 서버 정보를 가지고 ACTIVE인지 SLEEP인지 인식
	 */
	public void run(){

		try{
			HashMap<String, Object> argInfoVO = new HashMap<String, Object>();
			argInfoVO.put("AGENT_NAME", agentName);
			argInfoVO.put("MODULE_NAME", moduleName);

			ArrayList<HashMap<String, Object>> alist = null;
			while(true){
				alist = getAgentTime();
				
				for(int i=0; i< alist.size(); i++){
					HashMap<String, Object> map= (HashMap<String, Object>)alist.get(i);
					String serverName=(String)map.get("SERVER_NAME");
					int time = Integer.parseInt((String)map.get("TIME"));

					if(time > Integer.parseInt(agentTime)*3){
						init(agentTime);
					}

					if(serverName.equals(server)){
						//START DISTRIBUTION
						getDstbtData();

						//UPDATE AGENT RUN TIME
						updateEndProcDtm(argInfoVO);
					}
				}
				alist=null;
				Thread.sleep(Integer.parseInt(agentTime)*1000);
			}			
		}catch(Exception e){
			COMUtil.debug("[run-LINebDstbtThread] Exception : " + e.toString());
		}
	}

	////////////////////////////////////////////////////////////////////////////////////////
	//
	//	DISTRIBUTION METHOD
	//

	public void getDstbtData() throws Exception{

		String querySelectDistbLst;							//미배분 목록 조회 쿼리
		List<String> resultSelectDistbLst;					//미배분 목록 추출 목록
		List<HashMap<String, String>> listSelectDistbLst;	//미배분 목록 
		Iterator<HashMap<String, String>> itSelectDistbLst;	//미배분 목록 목록화
		
		//STEP 1 : 미 배분 목록 조회
		try{
			querySelectDistbLst = getSelectDistbLst();
			resultSelectDistbLst = WStringUtil.splitToListWithTrim("SUBS_NO ,SUBS_TYPE ,JDG_GRDE_CODE ,IS_SAVE_GD" , SPLIT ); 
			listSelectDistbLst = WQueryHelper.selectDefault(querySelectDistbLst, null, resultSelectDistbLst);

		}catch (Exception e) {
			COMUtil.debug("[Exception] STEP1 : " + e.toString() );
			throw new Exception("[Exception] STEP1 : " + e.toString() );
		}
		if(listSelectDistbLst==null){
			COMUtil.debug("[Exception] STEP1 :  listSelectDistbLst is NULL" );
			throw new Exception("[Exception] STEP1 : listSelectDistbLst is NULL" );
		}

		//STEP 1-1 : 배분 할당량 없으면 종료 됨.
		if( listSelectDistbLst.size() == 0 ){
			COMUtil.debug("[PASS] DISTRIBUTION COUNT IS ZERO." );
			return;
		}

		//STEP 2 : 배분시작
		try{
			itSelectDistbLst = listSelectDistbLst.iterator();
			COMUtil.debug("[DISTRIBUTION] START COUNT IS : " + listSelectDistbLst.size() );

			while(itSelectDistbLst.hasNext()){
				HashMap<String, String> cj = itSelectDistbLst.next();

				String subsNo = cj.get( SUBS_NO );
				String subsType = cj.get( SUBS_TYPE );
				String jdgGrdeCode = cj.get( JDG_GRDE_CODE );
				String isSaveGd = cj.get( IS_SAVE_GD );
				if( isSaveGd.equalsIgnoreCase("Y") ){
					jdgGrdeCode = G_CODES[0];	//저축성(1,4)은 초급(244001)에 할당된다.
				}
				
				//담당자 조회
				String selectChargedJudgementList = getSelectChargedJudgementList( jdgGrdeCode );
				List<String> resultChargedJudgementList = WStringUtil.splitToListWithTrim("JDG_NO, JDG_GRDE_CODE, WORK_ALT_YN" , SPLIT );
				List<HashMap<String, String>> listChargedJudgementList = WQueryHelper.selectDefault(selectChargedJudgementList, null, resultChargedJudgementList);
				if( listChargedJudgementList == null ){
					COMUtil.debug("[Exception] STEP2 :  listChargedJudgementList is NULL" );
					throw new Exception("[Exception] STEP2 : listChargedJudgementList is NULL" );
				}
					
					
				//담당자  수량이 0인 경우 : WORK_ALT_YN -> N 처리
				if( listChargedJudgementList.size() == 0 ){
					
					//UPDATE : WORK_ALT_YN -> ALL N
					String updateWorkAltN = getUpdateWorkAltN( jdgGrdeCode );
					int countWorkAltN = WQueryHelper.updateDefault(updateWorkAltN , null );
					COMUtil.debug("[UPDATE] updateWorkAltN [" + jdgGrdeCode + "]" + countWorkAltN );
					
					//RE SELECT : listChargedJudgementList
					listChargedJudgementList = WQueryHelper.selectDefault(selectChargedJudgementList, null, resultChargedJudgementList);
					if( listChargedJudgementList == null ){
						COMUtil.debug("[Exception] STEP3 :  listChargedJudgementList is NULL" );
						throw new Exception("[Exception] STEP3 : listChargedJudgementList is NULL" );
					}
				}
				
				//만약 그래도 담당자 수량이 0인 경우는 미배분 건으로 남는것임. 담당자가 지정 되어야 됨.
				//담당 심사자에게 심사배분을 실시함.
				if( listChargedJudgementList.size() > 0 ){
					HashMap<String, String> distbInfo = listChargedJudgementList.get(0);
					String jdgNo = distbInfo.get( JDG_NO );
					
					//UPDATE : WORK_ALT_YN -> Y 
					String updateWorkAltY = getUpdateWorkAltY( jdgNo );
					int countWorkAltY = WQueryHelper.updateDefault(updateWorkAltY , null );
					if( countWorkAltY != 1){
						COMUtil.debug("[Exception] STEP4 :  countWorkAltY is not 1 , [COUNT] : " + countWorkAltY );
						throw new Exception("[Exception] STEP4 : countWorkAltY is not 1 , [COUNT] : " + countWorkAltY );
					}
					
					//UPDATE : DISTRIBUTION INFO
					String updateDistbInfo = getUpdateDistbInfo( jdgNo , subsNo );
					int countDistbInfo = WQueryHelper.updateDefault(updateDistbInfo , null );
					if( countDistbInfo != 1){
						COMUtil.debug("[Exception] STEP5 :  countDistbInfo is not 1 , [COUNT] : " + countDistbInfo );
						throw new Exception("[Exception] STEP5 : countDistbInfo is not 1 , [COUNT] : " + countDistbInfo );
					}
					
					//INSERT : DISTRIBUTION INFO
					String insertJdgmtStat =  getInsertJdgmtStat(subsNo, jdgNo, subsType);
					int countInsertJdgmtStat = WQueryHelper.updateDefault(insertJdgmtStat , null );
					if( countInsertJdgmtStat != 1){
						COMUtil.debug("[Exception] STEP6 :  countInsertJdgmtStat is not 1 , [COUNT] : " + countInsertJdgmtStat );
						throw new Exception("[Exception] STEP6 : countInsertJdgmtStat is not 1 , [COUNT] : " + countInsertJdgmtStat );
					}
				}
				
				COMUtil.debug("[DISTRIBUTION] END ");
			}

		}catch (Exception e) {
			COMUtil.debug("[Exception] Distribution Error : " + e.toString() );
			throw new Exception("[Exception] Distribution Error : " + e.toString() );
		}
		
	}

	////////////////////////////////////////////////////////////////////////////////////////
	//
	//	QUERY
	//

	/**
	 * STEP 1
	 * 쿼리 : 미배분 목록 정보 얻어오기
	 * @return 쿼리
	 * @throws Exception 오류
	 */
	private String getSelectDistbLst() throws Exception
	{
		StringBuffer strSQL = new StringBuffer();

		try{
			strSQL.append("SELECT ");
			strSQL.append("    SUBS_NO, SUBS_TYPE ");
			strSQL.append("    , ( ");
			strSQL.append("        SELECT CODE ");
			strSQL.append("        FROM ");
			strSQL.append("        ( ");
			strSQL.append("            SELECT  CODE ");
			strSQL.append("                    , REGEXP_SUBSTR(CODE_EXPL,'[^|]+',1,1) M_FROM ");
			strSQL.append("                    , REGEXP_SUBSTR(CODE_EXPL,'[^|]+',1,2) M_TO ");
			strSQL.append("            FROM CO_CODE ");
			strSQL.append("            WHERE ");
			strSQL.append("                GRP_CODE = '244000' ");
			strSQL.append("        ) ");
			strSQL.append("        WHERE 1=1 ");
			strSQL.append("            AND TO_NUMBER(CNTR_AMT) > M_FROM ");
			strSQL.append("            AND TO_NUMBER(CNTR_AMT) <= M_TO) JDG_GRDE_CODE ");
			strSQL.append("    , CASE ");
			strSQL.append("        WHEN SUBSTR(GD_CODE,1,1) = '1' THEN 'Y' ");
			strSQL.append("        WHEN SUBSTR(GD_CODE,1,1) = '4' THEN 'Y' ");
			strSQL.append("      ELSE 'N' END IS_SAVE_GD ");
			strSQL.append("FROM ");
			strSQL.append("    LI_NEB_020 ");
			strSQL.append("WHERE 1=1 ");
			strSQL.append("    AND JDG_NO IS NULL ");
			strSQL.append("    AND JDGMT_OBJ_YN = 'Y' ");
			strSQL.append("    AND DEL_YN = 'N' ");
		}catch (Exception e) {
			COMUtil.debug("[Exception] getSelectDistbLst : " + e.toString() );
			throw new Exception("[Exception] getSelectDistbLst : " + e.toString() );
		}

		return strSQL.toString();
	}


	/**
	 * STEP 2
	 * 쿼리 : 담당 심사자 목록 조회
	 * @return 쿼리
	 * @throws Exception 오류
	 */
	private String getSelectChargedJudgementList(String jdgGrdeCode) throws Exception
	{
		StringBuffer strSQL = new StringBuffer();

		try{
			strSQL.append("SELECT ");
			strSQL.append("    JDG_NO, JDG_GRDE_CODE, WORK_ALT_YN ");
			strSQL.append("FROM ");
			strSQL.append("    LI_NEB_010 ");
			strSQL.append("WHERE 1=1 ");
			strSQL.append("    AND DEL_YN = 'N' ");
			strSQL.append("    AND VOC_YN = 'N' ");
			strSQL.append("    AND TO_CHAR(sysdate,'YYYYMMDD') >= VALD_STRT_DATE ");
			strSQL.append("    AND TO_CHAR(sysdate,'YYYYMMDD') <= VALD_END_DATE ");
			strSQL.append("    AND WORK_ALT_YN = 'N' ");
			strSQL.append("    AND JDG_GRDE_CODE = '" + jdgGrdeCode + "' ");
			strSQL.append("    AND ROWNUM = 1 ");
			strSQL.append("ORDER BY ");
			strSQL.append("    JDG_GRDE_CODE, JDG_NO ");
		}catch (Exception e) {
			COMUtil.debug("[Exception] getSelectChargedJudgementList : " + e.toString() );
			throw new Exception("[Exception] getSelectChargedJudgementList : " + e.toString() );
		}

		return strSQL.toString();
	}
	
	/**
	 * STEP 3
	 * 배분 여부 초기화(N) 처리 
	 * @param jdgGrdeCode 등급 코드  
	 * @return 쿼리
	 * @throws Exception 오류
	 */
	private String getUpdateWorkAltN(String jdgGrdeCode) throws Exception
	{
		StringBuffer strSQL = new StringBuffer();
		
		try{
			strSQL.append("UPDATE LI_NEB_010 ");
			strSQL.append("SET ");
			strSQL.append("    WORK_ALT_YN = 'N' ");
			strSQL.append("WHERE 1=1 ");
			strSQL.append("    AND JDG_GRDE_CODE = '" + jdgGrdeCode + "' ");	
		}catch (Exception e) {
			COMUtil.debug("[Exception] getUpdateWorkAltN : " + e.toString() );
			COMUtil.debug("[Parameter] jdgGrdeCode : " + jdgGrdeCode);
			throw new Exception("[Exception] getUpdateWorkAltN : " + e.toString() );
		}
		
		return strSQL.toString();
	}
	
	/**
	 * STEP 4
	 * 쿼리 : 심사자 배분 여부 업데이트
	 * @param jdgNo 심사자 번호
	 * @return 쿼리
	 * @throws Exception 오류
	 */
	private String getUpdateWorkAltY(String jdgNo) throws Exception
	{
		StringBuffer strSQL = new StringBuffer();

		try{
			strSQL.append("UPDATE LI_NEB_010 ");
			strSQL.append("SET ");
			strSQL.append("    WORK_ALT_YN = 'Y' ");
			strSQL.append("WHERE ");
			strSQL.append("    JDG_NO = '" + jdgNo + "' ");	
		}catch (Exception e) {
			COMUtil.debug("[Exception] getUpdateWorkAltY : " + e.toString() );
			COMUtil.debug("[Parameter] jdgNo : " + jdgNo);
			throw new Exception("[Exception] getUpdateWorkAltY : " + e.toString() );
		}

		return strSQL.toString();
	}

	/**
	 * STEP 5
	 * 쿼리 : 배분 정보 업데이트
	 * @param jdgNo 심사자 번호 
	 * @param subsNo 청약 번호 
	 * @return 쿼리 
	 * @throws Exception 오류
	 */
	private String getUpdateDistbInfo(String jdgNo, String subsNo) throws Exception
	{
		StringBuffer strSQL = new StringBuffer();

		try{
			strSQL.append("UPDATE ");
			strSQL.append("    LI_NEB_020 ");
			strSQL.append("SET ");
			strSQL.append("    JDG_NO = '" + jdgNo + "' ");
			strSQL.append("    , JDGMT_DISTB_DATE = TO_CHAR( SYSDATE , 'YYYYMMDD' ) ");
			strSQL.append("    , JDGMT_STAT_CODE = '20' ");
			strSQL.append("    , JDGMT_STAT_PROC_DATE = TO_CHAR( SYSDATE , 'YYYYMMDD' ) ");
			strSQL.append("    , JDGMT_DTL_STAT_CODE = '20' ");
			strSQL.append("    , JDGMT_DTL_STAT_PROC_DATE = TO_CHAR( SYSDATE , 'YYYYMMDD' ) ");
			strSQL.append("WHERE ");
			strSQL.append("    SUBS_NO = '" + subsNo +"' ");
		}catch (Exception e) {
			COMUtil.debug("[Exception] getUpdateDistbInfo : " + e.toString() );
			COMUtil.debug("[Parameter] jdgNo : " + jdgNo + ", subsNo : " + subsNo);

			throw new Exception("[Exception] getUpdateDistbInfo : " + e.toString() );
		}

		return strSQL.toString();
	}
	
	
	/**
	 * STEP 5
	 * 쿼리 : 심사 현황정보 등록
	 * @param subsNo 청약 번호  
	 * @param jdgNo 심사자 번호  
	 * @param subsType 청약 업무 구분 
	 * @return 쿼리 
	 * @throws Exception 오류
	 */
	private String getInsertJdgmtStat(String subsNo, String jdgNo, String subsType) throws Exception
	{
		StringBuffer strSQL = new StringBuffer();

		try{
			strSQL.append("INSERT INTO LI_NEB_030 ");
			strSQL.append("( ");
			strSQL.append("    SUBS_NO, PROC_DT, PROCMN_NO, PROC_OFFICE_CODE, SUBS_TYPE, JDGMT_STAT_CODE, JDGMT_DTL_STAT_CODE ");
			strSQL.append(") ");
			strSQL.append("VALUES ");
			strSQL.append("( ");
			strSQL.append("    '" + subsNo + "' , TO_CHAR(SYSDATE,'YYYYMMDDHH24MISS')||TO_CHAR(SYSTIMESTAMP,'FF3') ");
			strSQL.append("    , '" + jdgNo + "', (SELECT DEPT_CODE FROM LI_NEB_010 WHERE JDG_NO = '" + jdgNo + "') ");
			strSQL.append("    , '" + subsType + "', '20', '20' ");
			strSQL.append(") ");	
		}catch (Exception e) {
			COMUtil.debug("[Exception] getInsertJdgmtStat : " + e.toString() );
			COMUtil.debug("[Parameter] subsNo : " + subsNo + ", jdgNo : " + jdgNo + ", subsType : " + subsType);
			throw new Exception("[Exception] getInsertJdgmtStat : " + e.toString() );
		}

		return strSQL.toString();
	}

	///////////////////////////////////////////////////////////////////////////////////////////
	//
	//	FOR AGENT
	//

	/**
	 * AGENT INIT : 생명 인수 심사자 분배
	 * @param agentTime AGENT TIME (실행주기)
	 */
	public void init(String agentTime){

		try{
			COMUtil.debug("[LINebDstbtThread.init] Occured");
			
			//READ ENV
			Environment env = EnvManager.getEnvironment();
			this.agentTime = agentTime;
			this.server = COMUtil.HOSTNAME;

			//INIT INFO
			HashMap<String, Object> argInfoVO = new HashMap<String, Object>();
			argInfoVO.put("AGENT_NAME", agentName);
			argInfoVO.put("MODULE_NAME", moduleName);
			argInfoVO.put("SERVER_NAME", server);
			argInfoVO.put("AGENT_TIME", this.agentTime);
			
			//CHECK AGENT RUN TIME
			ArrayList<HashMap<String, Object>> alist = getAgentTime();
			for(int i=0; i< alist.size(); i++){
				HashMap<String, Object> map= (HashMap<String, Object>)alist.get(i);
				int time = Integer.parseInt((String)map.get("TIME"));	

				COMUtil.debug("[LINebDstbtThread] time :: " + time + " = agentTime :: " + agentTime);

				//RUN AGENT
				if(time > Integer.parseInt(agentTime)*5){
					updateData(argInfoVO);
				}
			}

		}catch(Exception e){
			COMUtil.debug("[LINebDstbtThread.init] Exception : " + e.toString());
		}
	}

	/**
	 * GET AGENT START INFO
	 * @return 시간정보 
	 * @throws Exception 오류
	 */
	public ArrayList<HashMap<String, Object>> getAgentTime() throws Exception {

		ArrayList<HashMap<String, Object>> alist = new ArrayList<HashMap<String, Object>>();

		Connection oConn = null;
		PreparedStatement pstmt = null;	
		ResultSet rs = null;

		StringBuffer sbQuery = new StringBuffer();

		COMUtil.debug(">>> [LINebDstbtThread.getAgentTime] Start... <<<");

		try{
			oConn = ConnectionPool.getConnection();
			COMUtil.debug(">>> DB Connection Success!!<<<");

			sbQuery.append("\n  SELECT round((sysdate- to_date(END_REG_DT, 'YYYYMMDDHH24MISS'))* 24 * 60 * 60) as TIME,		");
			sbQuery.append("\n  		SERVER_NAME ,																			");
			sbQuery.append("\n  		AGENT_TIME 																				");
			sbQuery.append("\n  FROM CO_AGENT_MNG 																		");
			sbQuery.append("\n  WHERE AGENT_NAME = ? 																			");
			sbQuery.append("\n      AND MODULE_NAME = ?																			");

			pstmt = oConn.prepareStatement(sbQuery.toString());
			pstmt.clearParameters();
			int i=1;
			pstmt.setString(i++, agentName);
			pstmt.setString(i++, moduleName);
			rs = pstmt.executeQuery();

			while (rs.next()){
				HashMap<String, Object> reMap = new HashMap<String, Object>();
				reMap.put("TIME", rs.getString("TIME"));
				reMap.put("SERVER_NAME", rs.getString("SERVER_NAME"));
				reMap.put("AGENT_TIME", rs.getInt("AGENT_TIME"));
				alist.add(reMap);
			}	
		}
		catch(Exception e) {
			COMUtil.debug("[LINebDstbtThread.getAgentTime] Exception : " + e.toString());
			throw new Exception("[LINebDstbtThread.getAgentTime] Exception:"+e.toString());
		}
		finally {
			if(rs != null) { rs.close(); rs=null;}
			if(pstmt != null){ pstmt.close(); pstmt=null;}
			if(oConn != null){ ConnectionPool.close(oConn); oConn=null;}
		}

		COMUtil.debug(">>> [LINebDstbtThread.getAgentTime] End... <<<");

		return alist;
	}

	/**
	 * UPDATE AGENT START TIME 
	 * @param argInfoVO AGENT INFO
	 * @return UPDATE COUNT 
	 * @throws Exception 오류
	 */
	public int updateData(HashMap<String, Object> argInfoVO) throws Exception {
		int returnVal=0;

		Connection oConn = null;
		PreparedStatement pstmt = null;		
		ResultSet rs = null;

		StringBuffer sbQuery = new StringBuffer();

		COMUtil.debug(">>> [LINebDstbtThread.updateData] Start... <<<");

		try{
			oConn = ConnectionPool.getConnection();

			sbQuery.append("\n  UPDATE CO_AGENT_MNG SET								");
			sbQuery.append("\n  	SERVER_NAME = ?	,										");
			sbQuery.append("\n  	AGENT_TIME = ?	,										");
			sbQuery.append("\n  	STRT_REG_DT = to_char(sysdate, 'YYYYMMDDHH24MISS'),	");
			sbQuery.append("\n  	END_REG_DT = to_char(sysdate, 'YYYYMMDDHH24MISS')		");
			sbQuery.append("\n  WHERE AGENT_NAME = ?										");
			sbQuery.append("\n      AND MODULE_NAME = ?										");

			pstmt = oConn.prepareStatement(sbQuery.toString());
			pstmt.clearParameters();
			int i=1;
			pstmt.setString(i++, (String)argInfoVO.get("SERVER_NAME"));
			pstmt.setString(i++, (String)argInfoVO.get("AGENT_TIME"));
			pstmt.setString(i++, (String)argInfoVO.get("AGENT_NAME"));
			pstmt.setString(i++, (String)argInfoVO.get("MODULE_NAME"));

			returnVal= pstmt.executeUpdate();
		}
		catch(Exception e){
			COMUtil.debug("[LINebDstbtThread.updateData] Exception : " + e.toString());
			throw new Exception("[LINebDstbtThread.updateData] Exception:"+e.toString());
		}
		finally{
			if(rs != null){ rs.close(); rs=null;} 
			if(pstmt != null){ pstmt.close(); pstmt=null;} 
			if(oConn != null){ ConnectionPool.close(oConn); oConn=null;}
		}

		COMUtil.debug(">>> [LINebDstbtThread.updateData] End... <<<");

		return returnVal;
	}

	/**
	 * UPDATE AGENT RUN TIME
	 * @param argInfoVO
	 * @return
	 * @throws Exception
	 */
	public Object updateEndProcDtm(HashMap<String, Object> argInfoVO) throws Exception {
		Object returnVal=0;

		Connection oConn = null;
		PreparedStatement pstmt = null;		
		ResultSet rs = null;

		StringBuffer sbQuery = new StringBuffer();

		COMUtil.debug(">>> [LINebDstbtThread.updateEndProcDtm] Start... <<<");

		try{
			oConn = ConnectionPool.getConnection();

			sbQuery.append("\n  UPDATE CO_AGENT_MNG SET								");
			sbQuery.append("\n  	END_REG_DT = to_char(sysdate, 'YYYYMMDDHH24MISS')		");
			sbQuery.append("\n  WHERE AGENT_NAME = ?										");
			sbQuery.append("\n      AND MODULE_NAME = ?										");

			pstmt = oConn.prepareStatement(sbQuery.toString());
			pstmt.clearParameters();
			int i=1;
			pstmt.setString(i++, (String)argInfoVO.get("AGENT_NAME"));
			pstmt.setString(i++, (String)argInfoVO.get("MODULE_NAME"));
			returnVal= pstmt.executeUpdate();
		}
		catch(Exception e){
			COMUtil.debug("[LINebDstbtThread.updateEndProcDtm] Exception : " + e.toString());
			throw new Exception("[LINebDstbtThread.updateEndProcDtm] Exception:"+e.toString());
		}
		finally{
			if(rs != null){ rs.close(); rs=null;} 
			if(pstmt != null){ pstmt.close(); pstmt=null;} 
			if(oConn != null){ ConnectionPool.close(oConn); oConn=null;}
		}

		COMUtil.debug(">>> [LINebDstbtThread.updateEndProcDtm] End... <<<");

		return returnVal;
	}


}
